package com.kaibes.web.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import com.kaibes.core.base.excetion.KaibesException;

public class CookieUtils {

    public static Cookie findByName(HttpServletRequest request, String name) throws KaibesException {
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (cookie.getName().equals(name)) {
                    return cookie;
                }
            }
        }
        throw new KaibesException("找不到cookie:"+name);
    }
}
